const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  console.log('代理服务器已启动');
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://192.168.137.202:8888',
      changeOrigin: true,
      pathRewrite: {
        '^/api': '/api'
      },
      onProxyReq: (proxyReq, req) => {
        console.log('\n========================= 代理请求日志 =========================');
        console.log('🔍 原始请求URL:', req.url);
        console.log('🎯 代理后的URL:', proxyReq.path);
        console.log('🌐 完整的目标URL:', 'http://192.168.137.202:8888' + proxyReq.path);
        console.log('==============================================================\n');
      },
      onError: (err, req, res) => {
        console.log('\n========================= 代理错误日志 =========================');
        console.log('❌ 代理请求错误:', err);
        console.log('==============================================================\n');
      }
    })
  );
}; 